package com.henme.crm.util.mybatis;

import com.henme.crm.util.page.Page;


public class OracleDialect implements Dialect {

    @Override
    public String getLimitString(Page page, String sql) {

        StringBuffer sqlBuffer = new StringBuffer(sql);
        int offset = (page.getPageNo() - 1) * page.getPageSize() + 1;
        sqlBuffer.insert(0, "select u.*, rownum r from (").append(") u where rownum < ").append(offset + page.getPageSize());
        sqlBuffer.insert(0, "select * from (").append(") where r >= ").append(offset);
        //上面的Sql语句拼接之后大概是这个样子：
        //select * from (select u.*, rownum r from (select * from t_user) u where rownum < 31) where r >= 16
        return sqlBuffer.toString();
    }
}
